package com.uidp.search;

import static com.uidp.hibernatelayer.AttributeTypeDAO.ATTRIBUTENAME;
import static org.apache.commons.lang.StringUtils.isNotEmpty;
import static org.hibernate.criterion.Restrictions.eq;

import com.acsior.sbc.exception.BusinessException;
import com.acsior.sbc.exception.SearchException;
import com.acsior.sbc.impl.hibernate.SearchHibernateBusinessObject;
import com.uidp.domain.AttributeType;
import com.uidp.hibernatelayer.AttributeTypeDAO;
import com.uidp.hibernatelayer.AttributeTypeVO;

public class AttributeTypeSearch
		extends
		SearchHibernateBusinessObject<AttributeTypeVO, AttributeTypeDAO, AttributeType> {

	private AttributeType attributeTypeCriteria;

	public AttributeTypeSearch() throws BusinessException {
		super();
	}

	public AttributeTypeSearch(String attributeName) throws BusinessException {
		this.attributeTypeCriteria.setAttributeName(attributeName);
	}

	/** @see SearchObject#initialize() */
	@Override
	protected final void initialize() throws BusinessException {
		super.initialize();

		this.attributeTypeCriteria = new AttributeType();
	}

	/** @see SearchHibernateBusinessObject#buildCriteria() */
	@Override
	protected void buildCriteria() throws SearchException {
		super.buildCriteria();
		if (isNotEmpty(getAttributeTypeCriteria().getAttributeName())) {
			getCriteria().add(eq(ATTRIBUTENAME, getAttributeTypeCriteria().getAttributeName()));
		}
	}

	@Override
	protected AttributeType createResultObject(AttributeTypeVO d)
			throws BusinessException {
		return new AttributeType(d);
	}

	@Override
	protected Class<AttributeTypeDAO> getDAOClass() {
		return AttributeTypeDAO.class;
	}

	public AttributeType getAttributeTypeCriteria() {
		return attributeTypeCriteria;
	}

	public void setAttributeTypeCriteria(AttributeType attributeTypeCriteria) {
		this.attributeTypeCriteria = attributeTypeCriteria;
	}

}
